<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<!DOCTYPE html>

<html>
<head>

<link rel="stylesheet" href="${ctx}/css/sapar.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/common.css" />

<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/sapar.js"></script>
<script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/js/mask.js"></script>
<script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
<script type="text/javascript">
	function getSelRecord(){
		var chk_value =[];
	   $('input[name="key"]:checked').each(function(){
			chk_value.push($(this).val()); 
		});
		return chk_value;
	}  
  
	//{depart:,package:,num:}

</script>
<style>

.add-box-first{
float:left;
}
.add-box-second{
float:left;
}
th{
border:1px solid #bdd0db;
}
#one{
width:411px;
}
#two{
width:411px;
}
#three{
width:170px;
}

#oneone{
width:200px;
}
#twotwo{
width:200px;
}

#threethree{
width:200px;
}

#fourfour{
width:200px;
}
#fivefive{
width:170px;
}
.gui-input{
width:97%;

margin-left:0px;
}
.table .table-operate a.buttona{background: #EFF6FA url("../../images/addico.png") no-repeat 4px 6px;
height: 30px;
text-align: center;
line-height: 30px;
width: 65px;
border-radius: 5px;
box-shadow: 1px 2px 3px;
margin-left: 15px;
margin-top: 5px;}

.table .table-operate a.buttona2{
 background: #EFF6FA url("../../images/delico.png") no-repeat 4px 6px;
height: 30px;
text-align: center;
line-height: 30px;
width: 65px;
border-radius: 5px;
box-shadow: 1px 2px 3px;
margin-left: 15px;
margin-top: 5px;
}
</style>


<title>团队票申请</title>
</head>

<body>
	<!-- 遮罩层 -->
	<div id="mask" class="mask"></div> 
    <div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
        <audio src="../../audio/Beep_Short.mp3" id="audio"></audio><!-- 成功提示音 -->
        <audio src="../../audio/Alarm_Clock (1).mp3" id="audio1"></audio><!-- 失败提示音 -->
        	<form class="create-order">
            <div class="subfiled clearfix">
                <h2>厂家器械回收</h2>
            </div>
            
            <div class="subfiled-content">
               <div class="user_management">
                   <div class="subfiled-style2 clearfix">
                    <h2>网篮信息</h2>
                   </div>
                   <div class="add-box clearfix">
                     <div class="add-box-first"   id="jiaojie">
                        <div class="kv-item clearfix">
                            <label>网篮条码：</label>
                            <div class="kv-item-content">
                                <input type="text" id="wanglantiaoma" name="huishouWanglanTiaoma" placeholder="网篮条码" autofocus="autofocus" min="1" maxlength="22" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                            </div>
                        </div>
                        <div class="kv-item clearfix" >
                            <label>网篮名称：</label>
                            <div class="kv-item-content">
                                <input type="text" name="huishouWanglanMingcheng" placeholder="网篮名称" readonly="readonly">
                            </div>
                        </div>
                      </div>
                      <div class="add-box-second" style="display: none;">
                        <div class="kv-item clearfix">
                            <label>网篮条码：</label>
                            <div class="kv-item-content">
                                <input type="text" name="huishouWanglanTiaomaSecond" placeholder="网篮条码" autofocus="autofocus" min="1" maxlength="22" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                            </div>
                        </div>
                        
                        <div class="kv-item clearfix">
                            <label>网篮名称：</label>
                            <div class="kv-item-content">
                                <input type="text" name="huishouWanglanMingchengSecond" placeholder="网篮名称" readonly="readonly">
                            </div>
                        </div>
                     </div>
                    </div>
               </div>
               <div class="user_management">
                    <div class="subfiled-style2 clearfix">
                      <h2>包数据</h2>
                   </div>
                              <!--表格开始-->
                <div class="table">
                    <!--表格操作-->
                    <div class="table-operate ue-clear" >
                    	<a href="javascript:;" class="add buttona" id="addpack">新增回收包</a>
                        <a href="javascript:;" class="del buttona2">全部删除</a>
                    </div>
                    <!--表格具体内容-->
                    <div class="table-box">
                        <table id="tpaTable">
                            <thead>
                                <tr> 
                                	<th id="one">科室</th>
                                    <th id="two">包名称</th>
                                    <th id="three">包数量</th>
                                    <th id="four">操作</th>
                                    <th id="five">多网篮</th>
                                </tr>
                            </thead>
                            <tbody id= "tpaTableBaby">
                            	<tr class="no-data package"><td colspan="10">暂时没有数据</td></tr>
                            </tbody>
                        </table>
                    </div>
                </div><!--表格结束-->
               </div>
               <div class="user_management">
                   <!-- 缺失登记 -->
	                <div class="subfiled-style2 clearfix">
	                    <h2>缺失信息</h2>
	                </div>
	                <div class="table">
	                   <div class="table-box">
	                        <table id="queshiTable">
	                            <thead>
	                                <tr>
	                                    <th id="oneone">缺失包名称</th>
	                                  	<th id="twotwo">缺失器械</th>
	                                    <th id="threethree">器械大小</th>
	                                    <th id="fourfour">器械形状</th>
	                                    <th id="fivefive">缺失数量</th>
	                                    <th>操作</th>
	                                </tr>
	                            </thead>
	                            <tbody>
	                                <tr class="no-data product"><td colspan="10">暂时没有数据</td></tr>
	                            </tbody>
	                        </table>
	                    </div>
                  </div>
               </div>
               <div class="user_management">
                      <!-- 人员信息录入 -->
	                <div class="subfiled-style2 clearfix">
	                    <h2>人员信息</h2>
	                </div>
	                   <div class="add-box clearfix"  id="jiaojie">
                        <div class="kv-item clearfix">
                            <label>交接人：</label>
                            <div class="kv-item-content">
                                <input @click="click" type="text" name="huishouJiaojierenTiaoma" placeholder="交接人" min="1" maxlength="22" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>回收人：</label>
                            <div class="kv-item-content">
                                <input type="text"  name="huishouHuishourenTiaoma" placeholder="回收人" min="1" maxlength="22" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                            </div>
                        </div>
                        
                        <div class="kv-item clearfix">
                            <div class="kv-item-content">
                                <a href="javascript:;"    class="sapar-btn sapar-btn-recom query-btn" id="save" >保存</a>
                            </div>
                        </div>
                    </div>
               </div> 
            </div>
            </form>
        </div>
        <div id="saper-ft" ></div>
    </div>
     
</body>

<script type="text/javascript">
window.onload = function(){
	$("#wanglantiaoma").focus();
}
$('select').iSelect();

//判断是否为空
function isNullOrEmpty(strVal){
	if(strVal !=null ){
		strVal = strVal.replace(/(^\s*)|(\s*$)/g,"");
	}
	if(strVal == '' || strVal == null || strVal == undefined){
		return true;
	}else{
		return false;
	}
}

$(function(){
	$(".add").click(function(){
		$("input[name='packNum']")
		layer.open({
			  type: 2,
			  title: '医疗包明细',
			  maxmin: true,
			  shadeClose: true, //点击遮罩关闭层
			  area : ['800px' , '520px'],
			  content: "${ctx}/wutiaoma/allDeptList.do"
			  });
	});
	//点击全部删除
	$(".del").click(function(){
		layer.confirm('你确定要删除全部包么？', function(index){
			$("#tpaTable tbody").empty();
			layer.close(index);
		});
		
	});
	//.index()获取当前行数
	$(".twowanglan").live('click',function(){
		if($(this).is(':checked')){
			var id = $(this).val();
			var index = $("#"+id+"").index();
			
			$("#tpaTableBaby tr:not(:eq("+index+"))").remove();
			
			$(".add-box-second").css('display','inline');
			
			$("#addpack").css('display','none');
			
		}else{
			$(".add-box-second").css('display','none');
			$("#addpack").css('display','inline');
		}
	})
	
	
	$(document).keydown(function(event){ 
		var oPlay0 = document.getElementById("audio");
		var oPlay1 = document.getElementById("audio1");
		console.log(oPlay0);
		console.log(oPlay1);
		var huishouWanglanTiaoma = $("input[name='huishouWanglanTiaoma']").val();
		if(event.keyCode==13){
		    if($("#wanglantiaoma").is(":focus") && !isNullOrEmpty(huishouWanglanTiaoma)) {
		    	$.ajax({
		            type: "GET",
		            url:"${ctx}/wutiaoma/findwanglan.do?huishouWanglanTiaoma="+huishouWanglanTiaoma,
		            error: function() {
		            },
		            success: function(data) {
		           	 if(data.status==true){
		           		var shuju = data.zsWanglan;
		           		$("input[name='huishouWanglanMingcheng']").val(shuju.wlMingcheng);
		           		if(!isNullOrEmpty($("input[name='huishouWanglanMingcheng']").val())){
		           			oPlay0.play();
		           			$("input[name='packNum']");
		           			layer.open({
		           				  type: 2,
		           				  title: '医疗包明细',
		           				  maxmin: true,
		           				  shadeClose: true, //点击遮罩关闭层
		           				  area : ['800px' , '520px'],
		           				  content: "${ctx}/wutiaoma/allDeptList.do"
		           			});
		           		}
		           	 }else if(data.status==false){
		           		 oPlay1.play();
		           		 if(data.msg==""){
		           			$("input[name='huishouWanglanTiaoma']").val("");
		           			$("input[name='huishouWanglanMingcheng']").val("");
		           		 }else{
		           			$("input[name='huishouWanglanTiaoma']").val("");
			           		$("input[name='huishouWanglanMingcheng']").val(""); 
		           		 }
		           		 
		           	 }
		            }
		        });
		    }
		    /* if($("#tpaTable tbody tr td").length > 1){
		    	alert($("#tpaTable tbody tr td").length);
		    } */
		    if(!isNullOrEmpty($("input[name='huishouHuishourenTiaoma']").val())){
		    		var check = true;
		     		var huishouJiaojierenTiaoma = $("input[name='huishouJiaojierenTiaoma']").val();
		     		var huishouHuishourenTiaoma = $("input[name='huishouHuishourenTiaoma']").val();
		     		var huishouWanglanMingcheng = $("input[name='huishouWanglanMingcheng']").val();
		     		$(".no-data").remove();
		     		var checkboxWanglan = $(".twowanglan").prop("checked");
		     		if(checkboxWanglan){
		     			var huishouWanglanTiaomaSecond = $("input[name='huishouWanglanTiaomaSecond']").val();
		     			if(isNullOrEmpty(huishouWanglanTiaomaSecond)){
		     				check = false;
		     				alert("网篮不能为空");
		     			}
		     		}
		     		
		     		//判断是否有包
		     		if($("#tpaTableBaby tr").length==0){
		     			check = false;
		     			alert("请添加包信息")
		     		}
		     		
		     		if(isNullOrEmpty(huishouJiaojierenTiaoma)||isNullOrEmpty(huishouHuishourenTiaoma)||isNullOrEmpty(huishouWanglanMingcheng)){
		     			check = false;
		     			alert("必填项不为空");
		     		}
		     		
		     		$('input[name="packNum"]').each(function(){
		    			if(isNullOrEmpty($(this).val())){
		    				check = false;
		    				alert("包数量不能为空")
		    			}
		    		});
		     		
		     		$('input[name="productqueshiNum"]').each(function(){
		    			if(isNullOrEmpty($(this).val())){
		    				check = false;
		    				alert("缺失数量不能为空")
		    			}
		    		});
		     		if(check){
		     //			$.myloading();
		     			showMask();
//		     			$(".query-btn").unbind("click");
		     			$(".query-btn").css("opacity","0.2");
		     			$.ajax({
		     	            type: "POST",
		     	            url:"${ctx}/wutiaoma/save.do",
		     	            data:$('.create-order').serialize(),// 你的formid
		     	            error: function(request) {
		     	           	 layer.alert("网络故障，请稍后再试!");
		     	            },
		     	            success: function(data) {
//		    	             $.myloading("hide");
//		    				 $(".query-btn").bind("click",function(){
		    					 
//		    				 });
		    				 $(".query-btn").css("opacity","1");
		    				 $("#mask").hide();
		     	           	 if(data.status=="true"){
		     	           		 layer.alert("回收成功,点击确定继续回收", function(index){
		     	           			window.location.href='huishou_wutiaoma.jsp';
		     	           		});
		     	           	 }else{
		     	           		 layer.alert(data.msg);
		     	           	 }
		     	            }
		     	        });
		     		}
		    	
		    }
		} 
	});
	
	//通过网篮条码生成网篮名称 网篮1 
	/* $("input[name='huishouWanglanTiaoma']").blur(function(){
		var huishouWanglanTiaoma = $("input[name='huishouWanglanTiaoma']").val();
		console.log(huishouWanglanTiaoma);
		$.ajax({
	            type: "GET",
	            url:"${ctx}/wutiaoma/findwanglan.do?huishouWanglanTiaoma="+huishouWanglanTiaoma,
	            error: function() {
	            },
	            success: function(data) {
	           	 if(data.status==true){
	           		var shuju = data.zsWanglan;
	           		
	           		$("input[name='huishouWanglanMingcheng']").val(shuju.wlMingcheng);
	           		
	           	 }else if(data.status==false){
	           		 if(data.msg==""){
	           			$("input[name='huishouWanglanMingcheng']").val("");
	           		 }else{
	           			layer.alert(data.msg);
		           		 
		           		$("input[name='huishouWanglanMingcheng']").val(""); 
	           		 }
	           		 
	           	 }
	            }
	        });
		
	}); */
	
	//通过网篮条码生成网篮名称 网篮1 
	$("input[name='huishouWanglanTiaomaSecond']").blur(function(){
		var huishouWanglanTiaoma = $("input[name='huishouWanglanTiaomaSecond']").val();
		console.log(huishouWanglanTiaoma);
		$.ajax({
	            type: "GET",
	            url:"${ctx}/wutiaoma/findwanglan.do?huishouWanglanTiaoma="+huishouWanglanTiaoma,
	            error: function() {
	           	 
	            },
	            success: function(data) {
	           	 if(data.status==true){
	           		var shuju = data.zsWanglan;
	           		
	           		$("input[name='huishouWanglanMingchengSecond']").val(shuju.wlMingcheng);
	           		
	           	 }else if(data.status==false){
	           		 if(data.msg==""){
	           			$("input[name='huishouWanglanMingchengSecond']").val("");
	           		 }else{
	           			layer.alert(data.msg);
		           		$("input[name='huishouWanglanMingchengSecond']").val("");
	           		 }
	           		 
	           	 }
	            }
	        });
	});
	

	
	
	$("#save").mouseover(function(){
		$("#save").css("background","#467735");
	})
	
	$("#save").mouseleave(function(){
		$("#save").css("background","#6ab96e");
	})
	$(".query-btn").click(function(){
		var check = true;
 		var huishouJiaojierenTiaoma = $("input[name='huishouJiaojierenTiaoma']").val();
 		var huishouHuishourenTiaoma = $("input[name='huishouHuishourenTiaoma']").val();
 		var huishouWanglanMingcheng = $("input[name='huishouWanglanMingcheng']").val();
 		$(".no-data").remove();
 		var checkboxWanglan = $(".twowanglan").prop("checked");
 		if(checkboxWanglan){
 			var huishouWanglanTiaomaSecond = $("input[name='huishouWanglanTiaomaSecond']").val();
 			if(isNullOrEmpty(huishouWanglanTiaomaSecond)){
 				check = false;
 				alert("网篮不能为空");
 			}
 		}
 		
 		//判断是否有包
 		if($("#tpaTableBaby tr").length==0){
 			check = false;
 			alert("请添加包信息")
 		}
 		
 		if(isNullOrEmpty(huishouJiaojierenTiaoma)||isNullOrEmpty(huishouHuishourenTiaoma)||isNullOrEmpty(huishouWanglanMingcheng)){
 			check = false;
 			alert("必填项不为空");
 		}
 		
 		$('input[name="packNum"]').each(function(){
			if(isNullOrEmpty($(this).val())){
				check = false;
				alert("包数量不能为空")
			}
		});
 		
 		$('input[name="productqueshiNum"]').each(function(){
			if(isNullOrEmpty($(this).val())){
				check = false;
				alert("缺失数量不能为空")
			}
		});
 		if(check){
 //			$.myloading();
 			showMask();
 			$(".query-btn").unbind("click");
 			$(".query-btn").css("opacity","0.2");
 			$.ajax({
 	            type: "POST",
 	            url:"${ctx}/wutiaoma/save.do",
 	            data:$('.create-order').serialize(),// 你的formid
 	            error: function(request) {
 	           	 layer.alert("网络故障，请稍后再试!");
 	            },
 	            success: function(data) {
//	             $.myloading("hide");
				 $("#mask").hide();
 	           	 if(data.status=="true"){
 	           		 layer.alert("回收成功,点击确定继续回收", function(index){
 	           			window.location.href='huishou_wutiaoma.jsp';
 	           		});
 	           	 }else{
 	           		 layer.alert(data.msg);
 	           	 }
 	            }
 	        });
 		}

 	});
	//跟据包回收
	

});


	



function callbackData(data){
	$(".package").remove();
	console.log(data);
	var str = '';
	for(var i = 0;i<data.length;i++){
		str += checkstr(data[i]);
	}
	$("#tpaTable tbody").append(str)
}
//
function checkstr(data){
	var obj = $("#" + data.depId+'_'+data.packId);
	console.log("id:"+obj);
	if(obj.length>0){
		//修改行之为数量 然后返回""
		var sum_pre = $("#"+data.packId).val();
		sum_next = parseInt(sum_pre) +  parseInt(data.packNum);
		$("#"+data.packId).val(sum_next);
		return "";
	}else{
		//console.log('<tr id="'+data.depId+'_'+data.packId+'"><td class="text-left">'+data.depVal+'</td><td class="text-left">'+data.packName+'</td><td class="text-left"><input type="hidden" name="packId" value="'+data.packId+'"/><input type="text"  class="gui-input" name="packNum"  id="'+data.packId+'" value="'+data.packNum+'"/></td><td><a href="javascript:;">删除</a>&nbsp;&nbsp;<a href="javascript:;" onclick="detail("'+data.packId+'")">查看明细</a></td></tr>');
		return '<tr id="'+data.depId+'_'+data.packId+'" value="'+data.packName+'"><td class="text-left">'+data.depVal+'</td>'
		+'<td class="text-left">'+data.packName+'</td><td class="text-left"><input type="hidden" name="packId" value="'+data.packId+'"/>'
		+'<input type="hidden" name="packName" value="'+data.packName+'"/><input type="text"  maxlength="3" onkeyup="this.value=this.value.replace(/\\D/g,\'\')"  class="gui-input" name="packNum"  id="'+data.packId+'" value="'+data.packNum+'"/></td>'
		+'<td><a href="javascript:;"  onclick="del(\''+data.depId+'_'+data.packId+'\')">删除</a>&nbsp;&nbsp;<a href="javascript:;" onclick="detail(\''+data.packId+'\',\''+data.packName+'\')">查看明细</a></td><td><input type="checkbox" class="twowanglan" value="'+data.depId+'_'+data.packId+'"></td></tr>'; 
	}
}



function ifcollbackdata(data){
	$(".product").remove();
	$.myloading();
		
	
	var packageId = data.packageId;
	var packageName = data.packageName;
	var qixiedata = data.qixiedata;
	var str ="";
	for(var i=0;i<qixiedata.length;i++){
		str += qixiestr(qixiedata[i],packageId,packageName);
	}
	$("#queshiTable tbody").append(str)
	
}


function qixiestr(data,packageId,packageName){
	var productId = data.productId;
	var productName = data.productName;
	var productSize = data.productSize;
	var productBarCode = data.productBarCode;
	var obj = $("#"+packageId+"_"+productId);
	console.log("id:"+obj);
	if(obj.length>0){
		return "";
	}else{
		return '<tr id="'+packageId+'_'+productId+'"><td><input type="hidden" name="productId" value="'+productId+'"/>'
		+'<input type="hidden" name="productName" value="'+productName+'"/>'
		+'<input type="hidden" name="packageId" value="'+packageId+'"/>'+packageName+' </td>'
		+'<td>'+productName+'</td><td>'+productSize+'<input type="hidden" name="productSize" value="'+productSize+'"/></td>'
		+'<td>'+productBarCode+'<input type="hidden" name="productBarCode" value="'+productBarCode+'"/></td>'
		+'<td><input type="text" name="productqueshiNum" class="gui-input" maxlength="2" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" value=""/>'
		+'</td> <td><a href="javascript:;" onclick="delqueshi(\''+packageId+'_'+productId+'\')">删除</a>&nbsp;&nbsp;</td></tr>';
	}
	
}


//点击table 右键删除行
function del(id){
	$("#"+id).remove();
}

function delqueshi(id){
	$("#"+id).remove();
}
//点击查询明细
function detail(id,name){
	layer.open({
		  type: 2,
		  title: name+'包明细',
		  maxmin: true,
		  shadeClose: true, //点击遮罩关闭层
		  area : ['800px' , '520px'],
		  content: '${ctx}/wutiaoma/findQixieList.do?id='+id+'&name='+name
		  });
}

/**
 * 算着玩但我的都说
 */



</script>
</html>